/* ======================================================================== */
/*  DMA Stream abstractions for Imaging.                                    */
/*                                                                          */
/*  These streams tie a large "external" buffer with a small "internal"     */
/*  buffer, and provide a generalized interface for streaming data to/from  */
/*  the external buffer from/to the internal buffer.                        */
/* ======================================================================== */


typedef enum dstr_dir_t
{
    DSTR_INPUT,
    DSTR_OUTPUT
} dstr_dir_t;


typedef struct dstr_t
{
    char           *x_data;     /* external data                        */
    int             x_ofs;      /* current offset into internal data    */
    unsigned        x_size;     /* length of external data buffer.      */
    char           *i_data;     /* internal data                        */
    unsigned short  i_ofs;      /* current offset into internal data    */
    unsigned short  i_size;     /* length of internal data buffer.      */
    unsigned short  w_size;     /* window size                          */
    unsigned short  quantum;    /* amount of data to move per transfer  */ 
    unsigned short  multiple;   /* mutiples of quantum to be transferred*/
    unsigned short  stride;     /* stride amount to increment ext. mem  */
    unsigned        xfer_id;    /* transfer ID to pend on.              */
} dstr_t;

/* ======================================================================== */
/*  DSTR_INIT    -- Initialize a new DMA Stream object.                     */
/* ======================================================================== */
int dstr_open
(
    dstr_t         *dstr,       /* DMA Stream structure.                    */
    void           *x_data,     /* "External" data buffer.                  */
    int             x_size,     /* Size of external data buffer.            */
    void           *i_data,     /* "Internal" data buffer.                  */
    unsigned short  i_size,     /* Size of internal data buffer.            */
    unsigned short  quantum,    /* Size of a single transfer (get or put)   */
    unsigned short  multiple,   /* Number of lines                          */ 
    unsigned short  stride,     /* Stride amount to increment ext. memory   */
    unsigned short  w_size,     /* Window size.  Set to 1 for double buf.   */     
    dstr_dir_t      dir         /* Direction (Input or Output)              */
);

/* ======================================================================== */
/*  DSTR_GET     -- Get the next buffer from a stream.                      */
/* ======================================================================== */
void * dstr_get(dstr_t *dstr);

/* ======================================================================== */
/*  DSTR_PUT     -- Write out the next buffer in a double-buffer.           */
/* ======================================================================== */
void *dstr_put(dstr_t *dstr); 


/* ======================================================================== */
/*  DSTR_GET     -- Get the next buffer using 2D transfer from a stream.    */
/* ======================================================================== */
void *dstr_get_2D(dstr_t *dstr);

/* ======================================================================== */
/*  DSTR_PUT     -- Write out using 2D transfer in a double-buffer.         */
/* ======================================================================== */
void *dstr_put_2D(dstr_t *dstr); 


int dstr_rewind
(
    dstr_t         *dstr,       /* DMA Stream structure.                    */
    void           *x_data,     /* "External" data buffer.                  */         
    dstr_dir_t      dir,
    unsigned short  w_size
);


/* ======================================================================== */
/*  DSTR_CLOSE     -- Close out the associated stream buffer.               */
/* ======================================================================== */

void dstr_close_2D(dstr_t *dstr);



/* ======================================================================== */
/*  End of file:  dstr_2D.h                                                 */
/* ------------------------------------------------------------------------ */
/*            Copyright (c) 2000 Texas Instruments, Incorporated.           */
/*                           All Rights Reserved.                           */
/* ======================================================================== */
